package top.cloudev.hello.slice;

import ohos.agp.components.Button;
import ohos.agp.components.Text;
import top.cloudev.hello.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;

public class MainAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        // 通过资源ID找到文本组件对象
        Text txt = (Text)findComponentById(ResourceTable.Id_text_helloworld);

        // 通过资源ID找到按钮组件对象
        Button button = (Button) findComponentById(ResourceTable.Id_btn_edit);
        // 监听按钮点击事件
        button.setClickedListener(component -> {
            // 设置文本对象的文字
            txt.setText("Hello Java UI");
        });
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
